//
//  BillsSinglePickView.m
//  Thinkape-iOS
//
//  Created by admin on 16/6/1.
//  Copyright © 2016年 TIXA. All rights reserved.
//

#import "BillsSinglePickView.h"
#import "KindsModel.h"
#import "BFKit.h"
#import "AppDelegate.h"
//#import "BillsSingleModel.h"

@interface BillsSinglePickView ()

@property (strong, nonatomic) UIPickerView *pickerView;
@property (strong, nonatomic) BillsSingleModel *selectModel;

@end

@implementation BillsSinglePickView

{
    //    NSArray *titleArr;
    NSInteger _index;
    NSInteger _colum_Two;
    
}


- (void)awakeFromNib
{
    self.selectModel = [[BillsSingleModel alloc] init];
    if (!self.pickerView) {
        self.pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 36, SCREEN_WIDTH, 162)];
        self.pickerView.delegate = self;
        self.pickerView.dataSource = self;
        [self addSubview:self.pickerView];
    }
    
}

- (void)setDataArray:(NSArray *)dataArray{
    if (self.dataArray != dataArray) {
        _dataArray = dataArray;
        _selectModel = [_dataArray firstObject];
        [self.pickerView reloadAllComponents];
//        for (int i = 0; i < 2; i ++) {
//            NSInteger row = [self.pickerView selectedRowInComponent:i];
//            [self resetColor:row component:i];
//        }
        
    }
}



#pragma mark - PickerViewDelegate

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

//    NSArray *arr = [self.dataArray safeObjectAtIndex:_index];
    if (self.dataArray) {
        return self.dataArray.count;
    }
    else
        return 0;
    
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)vie{
    
    UILabel *label = [[UILabel alloc] init];
  
    [label setFrame:CGRectMake(0, 0, 100, 15)];
    BillsSingleModel *model = [_dataArray safeObjectAtIndex:row];
    
    label.text = model.Name;
    
//        //wo
        AppDelegate *app=[UIApplication sharedApplication ].delegate;
        NSLog(@"传值%@",app.zhuanStr);
        
        app.zhuanStr=label.text;

    label.font = [UIFont systemFontOfSize:15];
    label.textColor = [UIColor colorWithHexString:@"333333"];
    return label;
    
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{

    return 100;

}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 35;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    _index = row;
    _colum_Two = 0;
    [self.pickerView reloadComponent:0];
    [self resetColor:_colum_Two component:0];
    
}

- (void)resetColor:(NSInteger )row component:(NSInteger )component{
    _selectModel = [self.dataArray safeObjectAtIndex:_index];
    
    // NSArray *arr = [self.dataArray safeObjectAtIndex:row];
//    _selectModel = [arr safeObjectAtIndex:0];
    
    NSLog(@"_selectModel :%@",_selectModel);
    UILabel *label = (UILabel *)[self.pickerView viewForRow:row forComponent:0];
    label.textColor = [UIColor colorWithRed:0.231 green:0.482 blue:0.824 alpha:1.000];
}

#pragma mark - 点击确定\取消按钮 调用

- (IBAction)SureBtnClick:(id)sender {
    self.transform = CGAffineTransformMakeTranslation(0, 799);
    if(self.selectItemCallBack){
        self.selectItemCallBack(_selectModel);
    }
    [self removeFromSuperview];
}

- (IBAction)CancelBtnClick:(id)sender {
    
    if (self.cancelClickBlock) {
        self.cancelClickBlock ();
    }
    
    [self removeFromSuperview];
}


@end
